let app = getApp();
let httptool=require("../../utils/zry.httptool.js");
Page({
  data:{
    concerns:[],
    UserId:'',
    conState:'',
    msgprop:'',//消息提示 
    mytype:1
  },
  onLoad:function(options){
    let that = this;
    let id = options.ID;
    console.log(id);
    let customerId = app.getStorage('customerId');
    that.setData({ UserId: customerId, mytype: options.ID});
    if(id==1){//我的关注列表
      wx.setNavigationBarTitle({ //动态设置头部标题
        title: '我的关注'
      })
     that.getConcernList();
    }else if(id==2){//我的粉丝列表
      wx.setNavigationBarTitle({
        title: '我的粉丝',
      })
      that.getFansList();
    }
  },
  getConcernList:function(){//获得关注列表
    let that=this;
    httptool.ajaxPost("/api/Fans/GetMyConcern", { UserId: that.data.UserId},function(res){
      if(res.suc){
          let data = app.notNull(res.data, []);
          for(let i in data){
            data[i].UserId=data[i].ID;
          }
          that.setData({concerns:data});
      }else{
         app.showNotify(that, res.msg);
      }

    });
  },
  getFansList:function(){//获得粉丝列表
      let that=this;
      httptool.ajaxPost("/api/Fans/GetMyFans", { UserId:that.data.UserId},function(res){
        if(res.suc){
            let data = app.notNull(res.data, []);
            that.setData({concerns:data});
        }else{
          app.showNotify(that, res.msg);
        }

    });
  },
  changeConcern:function(e){//关注列表的解除添加
    let that=this;
    let ConcernId=e.currentTarget.dataset.concernid;
    let param={};
    param.UserId = that.data.UserId;
    param.ConcernId = ConcernId;
    httptool.ajaxPost("api/Fans/AddOrDeleteFans", param, function(res){
        if(res.suc){
          let title="";
          if(res.data==1){
            title ="关注成功";
          }else if(res.data==0){
            title = "解除关注成功";
          }
          app.showSuccess({ msg: title });
          if (that.data.mytype == 1) {
            that.getConcernList();
          } else {
            that.getFansList();
          }          
        }else{
           app.showNotify(that, res.msg);
        }

    });
  },
  addConcern:function(e){//粉丝列表添加关注
    let that=this;
    let ConcernId=e.currentTarget.dataset.concernid;
    httptool.ajaxPost("api/Fans/AddOrDeleteFans", { UserId:that.data.UserId,ConcernId:ConcernId},function(res){
        if(res.suc){
          if(res.data==1){
            wx.showToast({
              title: "关注成功",
              duration: 1000,
              icon: "success"
            })
          }else if(res.data==0){
            wx.showToast({
              title: "解除关注",
              duration: 1000,
              icon: "success"
            })
          }
          that.getFansList();
        }else{
           app.showNotify(that, res.msg);
        }

    });
  },
 friendDetail:function(e){//点击头像进入某人的详情页，查看对方信息，帖子
    let that=this;
    let ToUserId = e.currentTarget.dataset.userid;
    wx.navigateTo({
      url: '../followdetail/followdetail?ToUserId='+ToUserId,
    });
  },
})